home *** CD-ROM | disk | FTP | other *** search
- Path: ohstpy.mps.ohio-state.edu!vancleef
- From: vancleef@ohstpy.mps.ohio-state.edu
- Newsgroups: comp.lang.c++
- Subject: Re: Need help in C
- Message-ID: <1996Jan24.033219.8806@ohstpy>
- Date: 24 Jan 96 03:32:19 -0500
- References: <4e4h29$3f2@cville-srv.wam.umd.edu>
- Organization: The Ohio State University, Department of Physics
-
- In article <4e4h29$3f2@cville-srv.wam.umd.edu>, leungyl@wam.umd.edu (David Leung) writes:
- > I am studying C/C++ and I arrived at a problem that I am stuck with.
- > I think it is easy for expericenced programmers, if you can help me
- > please email me at leungyl@wam.umd.edu
- >
- > this is the problem
- >
- > input a five digit number
- >
- > then, separate the five digits into 5 separate numbers and evaluate them
- > independently. Basically, cut the number into five pieces. This is what
- > I wrote.....
- >
-
- Read it in as a string and evalute each byte individually.
-
- -Garrett
-
-
- > cout << "Enter a five digit number: ";
- >
- > cin >> input;
- >
- >
- >
- > digi1 = input / 10000;
- >
- > digi2 = input / 1000 - digi1 * 10;
- >
- > digi3 = input / 100 - digi1 * 100 - digi2 * 10;
- >
- > digi4 = input / 10 - digi1 * 1000 - digi2 * 100 - digi3 * 10;
- >
- > digi5 = input - digi1 * 10000 - digi2 * 1000 - digi3 * 100 - digi4 * 10;
- >
- >
- >
- > cout << input << endl;
- >
- > cout << digi1 << endl;
- >
- > cout << digi2 << endl;
- >
- > cout << digi3 << endl;
- >
- > cout << digi4 << endl;
- >
- > cout << digi5 << endl;
- >
- >
- >
- >
- >
- >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- > the problem is, it work for some numbers, but for others it doesn't work.
- > Why? Can somebody help me??Thanks very much.
- >
- >
- > Regards,
- >
- >
- > David
- >
-